package test;

import com.ch01.pojo.Student;
import com.ch01.service.UserService;
import com.ch01.service.impl.StudentServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @ClassName Main
 * @Description TODO
 * @Author Kx
 * @Date 2025/4/27 9:35
 * @Version 1.0
 */
public class Main {
    public static void main(String[] args) {
        // 核心的上下文容器接口ApplicationContext
        // 1. 基于XML初始化的ApplicationContext
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        // 从容器中获取Bean对象
        // 使用泛型获取Bean对象
        UserService userService = context.getBean("studentService", StudentServiceImpl.class);

        // 如果这个接口仅有一个实现类的时候,可以直接使用Class对象获取
//        UserService userService = context.getBean(UserService.class);
        userService.add();

        // 获取Bean对象
        Student student = context.getBean("student", Student.class);

        System.out.println(student);
    }
}
